package org.jtzc.springaimcpservermvc;

import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

/**
 * @author wu chuang
 * @description
 */
@Service
public class FileSystemService {

    private final ResourceLoader resourceLoader ;

    @Autowired
    public FileSystemService(ResourceLoader resourceLoader) {
        this.resourceLoader = resourceLoader;
    }

    @Tool(name = "readFile", description = "读取本地文件内容")
    public String readFile(@ToolParam(description = "文件路径") String path) throws IOException {
        return Files.readString(Paths.get(path));
    }

    @Tool(name = "writeFile", description = "写入内容到本地文件")
    public String writeFile(
            @ToolParam(description = "文件路径") String path,
            @ToolParam(description = "文件内容") String content) throws IOException {
        Files.write(Paths.get(path), content.getBytes());
        return "写入成功";
    }


}
